#include <FreeRTOS.h>
#include <task.h>
#include <stdio.h>
#include <bl_sys_time.h>
#include <cli.h>
#include <easyflash.h>
#include <bl_timer.h>
 
#define string_key "string"     //设置字符串的key值
#define int_key    "int"        //设置整形数据的key值

static void write_read_string(void)     //字符串读写
{
    size_t len;
    char string_write[]={"hello world"};
    char string_read[20];
    ef_set_env_blob(string_key,string_write,sizeof(string_write));  //写入字符串
    vTaskDelay(50);

    size_t size=ef_get_env_blob(string_key,string_read , sizeof(string_read), &len);    //读出字符串
    if (size ==0){
        printf("[NV] get string_read fail \r\n");
        return false;
    }else{
        printf("read string:%s\r\n",string_read);
    }    

    ef_del_env(string_key);   //删除字符串
}

static void write_read_int(void)    //整形数据读写
{
    size_t len;
    int write;
    int read;

    write=8848;
    ef_set_env_blob(int_key,&write,sizeof(write));     //写入整形数据 
    vTaskDelay(pdMS_TO_TICKS(50));
    size_t size = ef_get_env_blob(int_key,&read , sizeof(read), &len);   //读出整形数据 
    if(size==0)
    {
        printf("[NV] get int fail \r\n");
    }
    else
    {
        printf("read int:%d\r\n",read);
    }

    ef_del_env(int_key);  //删除整形数据 
}

static void proc_main_entry(void *pvParameters)
{
    easyflash_init();   //flash初始化

    write_read_string();
    write_read_int();

    vTaskDelete(NULL);
}

void main()
{
    puts("[OS] proc_main_entry task...\r\n");
    xTaskCreate(proc_main_entry, (char*)"main_entry", 1024, NULL, 15, NULL);
}
